#pragma once

#include "AdpcmCapturerRender.h"
#include <atlcomcli.h>
#include <memory>

using namespace std;


class AdpcmCapturer
{
public:
	AdpcmCapturer(int channels, int sampleRate, int bitsPerSample, int bitrate, AudioCodecId codecId, CaptureAudioCallBack callback, int deviceIndex, HAUDIOSESSION newSessionId);
	~AdpcmCapturer(void);

	bool IsInitialized() { return m_isInitialized;}

	int SetVolume(int volume);
	int GetVolume();

	static void ClearCaptureDevice();
	static int EnumCaptureDevice();

	static int GetCaptureDeviceNum();
	static int GetCaptureDeviceName(int deviceIndex, char *buf, int len);

private:
	AdpcmCapturer(void) {}

	bool m_isInitialized;
	
	int m_deviceIndex;
	int m_channels;
	int m_sampleRate;
	int m_bitsPerSample;
	int m_bitrate;
	AudioCodecId m_codecId;
	UINT m_volume;
	CaptureAudioCallBack m_callback;
	HAUDIOSESSION m_sessionId;

	CComPtr< IBaseFilter > m_captureSource;
	CComQIPtr< IGraphBuilder > m_filterGraph;
	CComQIPtr< ICaptureGraphBuilder2 > m_graphBuilder;
	auto_ptr<CAdpcmCaptureRender> m_captureRender;

	int InitCapturer();
	int DestroyCapturer();
	bool StartCapture();
	void StopCapture();
};
